package main

import "fmt"

func groupThePeople(groupSizes []int) (res [][]int) {
	groupMap := map[int][]int{}
	for index, v := range groupSizes {
		groupMap[v] = append(groupMap[v], index)
	}
	for k, v := range groupMap {
		for i := 0; i < len(v); i += k {
			res = append(res, v[i:i+k])
		}
	}
	return res
}

func main() {
	fmt.Printf("%+v\n", groupThePeople([]int{3, 3, 3, 3, 3, 1, 3}))
	fmt.Printf("%+v\n", groupThePeople([]int{2, 1, 3, 3, 3, 2}))
}
